import logo.Mlog
from dataTemp.action import Action
from dataTemp.step import Step


class Task:
    # 任务名字
    name: str = None
    # 任务时常
    limit_time: int = None
    # 任务完成时间
    complete_time: int = None
    # 任务进度
    __rate: int = 0
    # 任务是否完成
    is_complete: bool = False
    # 任务列表
    actions: [Action] = []
    # 当前步骤
    curr_step: Step = None

    # 始终从第一个开始取
    def get_action(self) -> Action:
        if len(self.actions) == self.__rate:
            self.is_complete = True
            return None
        # logo.Mlog.logger.debug(self.__rate)
        a = self.actions[self.__rate]
        self.__rate += 1
        return a

    def run_action(self):
        action = None
        while True:
            # 当前动作完成了进入下一个动作
            action = self.get_action()
            # 判断整个任务是否完成了
            if self.is_complete:
                logo.Mlog.logger.debug(f"{self.name}=任务完成")
                return
            action.start()
            logo.Mlog.logger.debug(f"{action.name}=action.name")


    def add_action(self, action: Action):
        self.actions.append(action)
